<template>
  <div style="padding: 15px;">
    <vxe-toolbar id="warehouseLocationId" :custom="{storage: true}" export :refresh="{query: findList}">
      <template v-slot:buttons>
        <el-button @click="findList">查询</el-button>
        <el-button :disabled="printFlag" @click="funcCreateBatchTask('PICKING')">拣货批量下发</el-button>
        <el-button :disabled="printFlag" @click="funcCreateBatchTask('CHECK')">复核批量下发</el-button>
        <el-button :disabled="printFlag" @click="printGeneralPicking">打印总拣单</el-button>
        <el-button v-bind:disabled="printFlag" @click="funcPrint(0)">打印拣货单</el-button>
        <el-button v-bind:disabled="printFlag" @click="funcPrint(1)">打印拣货单(序号)</el-button>
        <el-button v-bind:disabled="printFlag" @click="printWaybill">打印运单</el-button>
        <el-input class="wavePickingCode" placeholder="请输入波次号" clearable v-model.trim="wavePickingCode" @keyup.enter.native="printWavePick" />
        <el-button :disabled="!wavePickingCode" @click="printWavePick">波次打印</el-button>
      </template>
    </vxe-toolbar>
    <vxe-table
      ref="xTable"
      border
      resizable
      stripe
      highlight-current-row
      :align="allAlign"
      show-footer
      highlight-hover-row
      row-id="id"
      class="mytable-footer"
      :export-config='{type:"csv"}'
      height="700"
      :loading="loading"
      :data="tableData"
      :edit-config="{trigger: 'click', mode: 'row', showStatus: true}"
      sort-config.remote
      @sort-change="sortList"
      auto-resize
      :seq-config="{startIndex: listQuery.pageNum * listQuery.pageSize - listQuery.pageSize}"
    >
      <vxe-table-column type="seq" width="60"></vxe-table-column>
      <vxe-table-column type="checkbox" width="60"></vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="status" title="状态" min-width="150" sortable show-header-overflow show-overflow :formatter="formatterStatus"/>
        <template v-slot:header="{ column }">
          <el-select v-model="listQuery.status" placeholder="请选择状态" clearable>
            <el-option
              v-for="item in statusList"
              :key="item.code"
              :label="item.name"
              :value="item.code"
            />
          </el-select>
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="pickingPrintCount" title="总拣单打印状态" min-width="150" sortable show-header-overflow show-overflow :formatter=" ({ cellValue })=> cellValue > 0 ? '是':'否' "/>
        <template #header>
          <el-select v-model="listQuery.pickingPrintCount" placeholder="请选择状态" clearable>
            <el-option
              v-for="item in issueList"
              :key="item.code"
              :label="item.name"
              :value="item.code"
            />
          </el-select>
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="waybillPrintCount" title="运单打印状态" min-width="150" sortable show-header-overflow show-overflow :formatter=" ({ cellValue })=> cellValue > 0 ? '是':'否' "/>
        <template #header>
          <el-select v-model="listQuery.waybillPrintCount" placeholder="请选择状态" clearable>
            <el-option
              v-for="item in issueList"
              :key="item.code"
              :label="item.name"
              :value="item.code"
            />
          </el-select>
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="pickingSortPrintCount" title="拣货单(序号)打印状态" min-width="180" sortable show-header-overflow show-overflow :formatter=" ({ cellValue })=> cellValue > 0 ? '是':'否' "/>
        <template #header>
          <el-select v-model="listQuery.pickingSortPrintCount" placeholder="请选择状态" clearable>
            <el-option
              v-for="item in issueList"
              :key="item.code"
              :label="item.name"
              :value="item.code"
            />
          </el-select>
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="issue" title="是否下发" min-width="150" sortable show-header-overflow show-overflow :formatter="formatterIssue"/>
        <template v-slot:header="{ column }">
          <el-select v-model="listQuery.issue" placeholder="请选择" clearable>
            <el-option
              v-for="item in issueList"
              :key="item.code"
              :label="item.name"
              :value="item.code"
            />
          </el-select>
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="orderTag" title="订单标识" min-width="150" sortable show-header-overflow show-overflow :formatter="formatterOrderTag"/>
        <template v-slot:header="{ column }">
          <el-select v-model="listQuery.orderTag" placeholder="请选择" clearable>
            <el-option
              v-for="item in orderTagList"
              :key="item.code"
              :label="item.name"
              :value="item.code"
            />
          </el-select>
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="warehouseName" title="仓库" min-width="150" show-header-overflow show-overflow/>
        <template #header>
          <warehouseSelect :selected="false" @setWarehouseCode="(val)=>{listQuery.warehouseCode = val}" style="width: 100%"/>
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="shipmentName" title="入驻商" min-width="150" show-header-overflow show-overflow />
        <template #header>
          <shipmentSelect ref="shipmentSelect" url="/wms/warehouseShipment/business/shipments" @setCustomerCode="setShipmentCode" style="width: 100%"/>
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="carrierName" title="承运商" min-width="150" show-header-overflow show-overflow/>
        <template #header>
          <el-select v-model="listQuery.carrierCode" placeholder="请选择" clearable>
            <el-option
              v-for="item in carrierList"
              :key="item.code"
              :label="item.name"
              :value="item.code"
            />
          </el-select>
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="code" title="拣货单号" min-width="200" sortable show-header-overflow show-overflow/>
        <template v-slot:header="{ column }">
          <el-input v-model="listQuery.code" placeholder="请输入拣货单号" clearable />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="sourceCode" title="来源单号" min-width="200" sortable />
        <template v-slot:header="{ column }">
          <el-input v-model="listQuery.sourceCode" placeholder="请输入来源单号" clearable />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="wavePickingCode" title="波次号" min-width="200" sortable />
        <template v-slot:header="{ column }">
          <el-input v-model="listQuery.wavePickingCode" placeholder="请输入波次号" clearable />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="typeText" title="单据类型" min-width="200" sortable/>
        <template v-slot:header="{ column }">
          <el-select v-model="listQuery.type" placeholder="请选择单据类型" clearable>
            <el-option
              v-for="item in typeList"
              :key="item.code"
              :label="item.name"
              :value="item.code"
            />
          </el-select>
        </template>
      </vxe-table-column>

      <vxe-table-column>
        <vxe-table-column field="planQuantity" title="计划数量" min-width="200" sortable />
        <template v-slot:header="{ column }">
          <el-input v-model="listQuery.planQuantityStart" placeholder="下限" type='number' style="width:80px;" />
          -
          <el-input v-model="listQuery.planQuantityEnd" placeholder="上限" type='number' style="width:80px;" />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="pickingQuantity" title="拣货数量" min-width="200" sortable />
        <template v-slot:header="{ column }">
          <el-input v-model="listQuery.pickingQuantityStart" placeholder="下限" type='number' style="width:80px" />
          -
          <el-input v-model="listQuery.pickingQuantityEnd" placeholder="上限" type='number' style="width:80px;" />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="notPickingQuantity" title="待拣数量" min-width="200" sortable />
        <template v-slot:header="{ column }">
          <el-input v-model="listQuery.notPickingQuantityStart" placeholder="下限" type='number' style="width:80px;" />
          -
          <el-input v-model="listQuery.notPickingQuantityEnd" placeholder="上限" type='number' style="width:80px;" />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="createdName" title="创建人" min-width="150" sortable />
        <template v-slot:header="{ column }">
          <el-input v-model="listQuery.createdName" placeholder="请输入创建人" clearable />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="gmtCreated" title="创建时间" min-width="400" sortable show-header-overflow show-overflow />
        <template v-slot:header="{ column }">
          <el-date-picker
            v-model="listQuery.gmtCreatedRange"
            type="datetimerange"
            value-format="yyyy-MM-dd HH:mm:ss"
            :picker-options="pickerOptions"
            style="width:100%"
            range-separator="至"

            start-placeholder="开始日期"
            end-placeholder="结束日期"
            @change="value => changeDate(value, 'gmtCreated')"
          />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column
          field="pickingCompletionTime"
          show-header-overflow
          show-overflow
          title="拣货完成时间"
          min-width="420"
          sortable
          :resizable="false"
        />
        <template v-slot:header>
          <el-date-picker
            v-model="listQuery.pickingCompletionTimeRange"
            type="datetimerange"
            value-format="yyyy-MM-dd HH:mm:ss"
            :picker-options="pickerOptions"
            style="width:100%"
            range-separator="至"

            start-placeholder="开始日期"
            end-placeholder="结束日期"
            @change="value => changeDate(value, 'pickingCompletionTime')"
          />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="modifiedName" title="修改人" min-width="150" sortable />
        <template v-slot:header="{ column }">
          <el-input v-model="listQuery.modifiedName" placeholder="请输入修改人" clearable />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="gmtModified" title="修改时间" min-width="400" sortable />
        <template v-slot:header="{ column }">
          <el-date-picker
            v-model="listQuery.gmtModifiedRange"
            type="datetimerange"
            popper-class="popper-left"
            value-format="yyyy-MM-dd HH:mm:ss"
            :picker-options="pickerOptions"
            style="width:100%"
            range-separator="至"

            start-placeholder="开始日期"
            end-placeholder="结束日期"
            @change="value => changeDate(value, 'gmtModified')"
          />
        </template>
      </vxe-table-column>
      <vxe-table-column title="操作" fixed="right" min-width="150">
        <template slot-scope="scope">
          <el-tooltip content="下发" placement="top" v-if="scope.row.status == '0' && scope.row.issue == '0'">
            <vxe-button type="text" @click="funcCreateTask(scope.row.code, scope.row.wavePickingCode)">
              <i class="el-icon-s-promotion"/>
            </vxe-button>
          </el-tooltip>
          <el-tooltip content="拣货" placement="top" v-if="scope.row.status == '0' || scope.row.status == '1'">
            <vxe-button type="text" @click="funcCheck(scope.row.code, scope.row.wavePickingCode, scope.row.temporaryCode)">
              <i class="iconfont icon-zhuangchedanguanli"/>
            </vxe-button>
          </el-tooltip>
          <el-tooltip content="查看" placement="top">
            <vxe-button type="text" @click="funcDetail(scope.row.code, scope.row.wavePickingCode, scope.row.temporaryCode)">
              <i class="el-icon-document"/>
            </vxe-button>
          </el-tooltip>
        </template>
      </vxe-table-column>
    </vxe-table>
    <vxe-pager
      :loading="loading"
      :current-page.sync="listQuery.pageNum"
      :page-size.sync="listQuery.pageSize"
      :total="listQuery.total"
      :layouts="['PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump', 'Sizes', 'FullJump', 'Total']"
      @page-change="handlePageChange"
    />
    <vxe-modal v-model="modelGeneralPickingFlag" title="打印总拣单" width="600" height="600" destroy-on-close>
      <printFaceSheet :printData="printCustomData" @finshPrint="generalPickingFinsh" />
    </vxe-modal>
    <vxe-modal v-model="modelPrintFlag" title="打印拣货单" width="900" height="800" destroy-on-close resize>
      <compPrint v-if="!isPrintSeq" :printData="printData" />
      <compPrintSeq v-else :printData="printData" @finshPrint="findList(),funcPrint()" />
    </vxe-modal>
    <vxe-modal v-model="printExpressBillmodel" title="打印运单" width="600" height="600" destroy-on-close>
      <printExpressBill :printData="printCustomData" titleTemplate="选择标准运单模板" :parcelType="parcelType" @finshPrint="openClosePrintMode(), printCustomData=[]" />
    </vxe-modal>
  </div>
</template>
<script>
import Vue from 'vue'
import 'xe-utils'
import VXETable from 'vxe-table'
import 'vxe-table/lib/index.css'
import XEUtils from 'xe-utils'
import VXEUtils from 'vxe-utils'
Vue.use(VXETable, VXEUtils, XEUtils, { mounts: ['cookie'] })
import compPrint from './components/print.vue'
import compPrintSeq from './components/printSeq.vue'
import printExpressBill from '@/components/Printing'
import printFaceSheet from '@/components/Printing/custom.vue'
import { pickingList, printGeneralPickOrders, batchGeneralPickCount, getInfoByWavePickingCode } from '@/api/outStorage'
import { createTask, createBatchTask } from '@/api/store'
import '@/assets/iconfont/iconfont.css'
import { carrierList } from '@/api/outStorage'
import warehouseSelect from '@/views/components/warehouseSelect.vue'
import shipmentSelect from '@/views/components/shipmentSelect.vue'
import soonPrint from '@/components/Printing/printBefore.js'
export default {
  name: '拣货单管理',
  components: {
    warehouseSelect,
    shipmentSelect,
    compPrint,
    compPrintSeq,
    printFaceSheet,
    printExpressBill
  },
  data() {
    return {
      isPrintSeq: false, // 打印带序号版本
      message: '',
      initFinishFlag: false,
      modelPrintFlag: false, //打印开关
      modelGeneralPickingFlag: false, //打印总拣单

      // 日期选项
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
      loading: false,
      allAlign: 'center',
      tableData: [],
      modelAddFlag: false,
      modelEditFlag: false,
      modelDetailFlag: false,
      statusList:[                       //状态
        { code: "0", name: "待拣货" },
        { code: "1",name: "拣货中" },
        { code: "2",name: "拣货完成" },
      ],
      typeList: [
          { code: '0', name: '销售出库' },
          { code: '1', name: '报损出库' },
          { code: '2', name: '领用出库' },
          { code: '3', name: '盘亏出库' },
          { code: '4', name: '采购退货' },
          { code: '5', name: '调拨退货' },
      ],
      orderTagList: [
        {code: '1', name:'单品单件'},
        {code: '2', name:'单品多件'},
        { code: '3', name: '多品' },
        { code: '4', name: '爆品' },
        { code: '5', name: '按单' }
      ],
      copy: false,
      issueList: [
        {code: '0', name:'否'},
        {code: '1', name:'是'},
      ],
      carrierList: [], // 承运商列表
      wavePickingCode: '',
      listQuery: {
        total: 0,             //总数
        createdByName:'',         //创建人
        modifiedByName:'',        //修改人
        gmtCreated:'',        //创建时间
        gmtModified:'',       //修改时间
        code:'',                                                //拣货单号 ,
        notPickingQuantity:'',                                  //待拣数量 ,
        pickingQuantity:'',                                     //拣货数量 ,
        planQuantity:'',                                        //计划数量 ,
        remarks:'',                                             //备注 ,
        shipmentCode:'',                                        //入驻商 ,
        deliveryCode:'',                                          //来源单号 ,
        wavePickingCode:'', //波次号
        status:'0',                                              //状态 ,
        typeText:'',                                                //单据类型 ,
        warehouseCode:'',                                       //仓库
        carrierCode: '',
        pageNum: 1,
        pageSize: 10,
        sortField: '',
        sortType: '',
        planQuantityStart: '',
        pickingQuantityStart: '',
        notPickingQuantityStart: '',
        planQuantityEnd: '',
        pickingQuantityEnd: '',
        notPickingQuantityEnd: '',
        issue: '',
      },
      printData: [], // 要打印的数据
      printCustomData: [], // 要打印的自定义数据

      parcelType: '', // 哪家快递
      printExpressBillmodel: false, //打印运单
      needLoadList: false // 在keep-live钩子函数activated内是否需要加载列表
    }
  },
  created() {
    this.findList()
    this.$eventBus.$on('printFinish', () => this.wavePickingCode = '')

    this.$eventBus.$on("refreshList", () => {
      this.listQuery.status = '0'
      this.findList()
    })
    window.onstorage = ({key}) => {
      if (key.indexOf('printComplete') != -1) {
        this.$message.success('打印任务执行完毕~')
        this.findList()
        this.$refs.xTable.clearCheckboxRow()
        localStorage.removeItem(key)
      }
    }
  },
  computed: {
    'printFlag': function() {
      if(this.initFinishFlag) {
        let selectRecords = this.$refs.xTable.getCheckboxRecords();
        if(selectRecords.length > 0) {
          return false;
        } else {
          return true;
        }
      }
      return true;
    }
  },
  activated() {
    const { meta: { noCache } } = this.$route
    if (!noCache && this.needLoadList) this.findList()
  },
  methods: {
    // 根据入驻商获取承运商列表
    getCarrierList(shipmentCode){
      this.carrierList = []
      this.listQuery.carrierCode = ''
      if (shipmentCode) {
        carrierList(shipmentCode).then(res => {
         this.carrierList = res.data.records
       })
      }
    },
    // 选中入驻商列表某条数据
    setShipmentCode(value) {
      this.getCarrierList(value)
      this.listQuery.shipmentCode = value
    },
    // 打印总拣单前
    printGeneralPicking() {
      let arr = [], printed = []
      let selectRecords = this.$refs.xTable.getCheckboxRecords()
      selectRecords.forEach( i => {
        arr.push(i.code)
        if (i.pickingPrintCount > 0) printed.push(i.code)
      })
      if (printed.length > 0) {
        this.$confirm('您选择的单据已经打印过，请确认是否继续？', '提示', {
          type: 'warning'
        }).then(() => {
          this.printGeneralPickOrders(arr)
        }).catch(() => {})
      } else {
        this.printGeneralPickOrders(arr)
      }
    },
    // 打印总拣单
    printGeneralPickOrders(arr) {
      printGeneralPickOrders(arr).then(res => {
        if (res.status === 0 && res.data.length > 0) {
          this.printCustomData = res.data
          this.modelGeneralPickingFlag = true
        }
      })
    },
    // 打印总拣单完成
    generalPickingFinsh() {
      this.modelGeneralPickingFlag = false
      const codes = this.printCustomData.map(item => item.code)
      batchGeneralPickCount(codes).then(res => this.findList()).finally(()=>this.printCustomData = [])
    },
    //打印
    funcPrint(type) {
      if (type) {
        this.isPrintSeq = !!type
        let arr = []
        let selectRecords = this.$refs.xTable.getCheckboxRecords()
        selectRecords.forEach( i => {
          arr.push(i.code)
        })
        this.printData = arr
      }
      this.modelPrintFlag = !this.modelPrintFlag
    },
    //打印运单
    printWaybill() {
      let arr = []
      let selectRecords = this.$refs.xTable.getCheckboxRecords()
      if (selectRecords.length === 1) {
        localStorage.setItem('printCode', selectRecords[0].code)
        let routeUrl = this.$router.resolve({
          path: '/printResult',
          query: {
            type: 'string',
            listInterface: 'printPickOrder'
          }
        })

        // window.open(routeUrl.href, '_blank')
        soonPrint(routeUrl.href)
        // if (selectRecords[0].waybillPrintCount > 0) {
        //   this.$confirm('您选择的单据已经打印过，请确认是否继续？', '提示', {
        //     type: 'warning'
        //   }).then(() => soonPrint(routeUrl.href)).catch(() => {})
        // } else {
        //   soonPrint(routeUrl.href)
        // }
        // selectRecords.forEach( i => {
        //   arr.push(i.code)
        // })
        // const rLoading = this.openLoading({
        //   text: '打印中，请勿动！...',
        //   duration: 'n'
        // })
        // printExpress2(arr[0]).then(res => {
        //   if (res.status === 0 && res.data.length > 0) {
        //     console.log('printExpress----->',res.data);
        //     rLoading.close()
        //     new PrintWaybill({ printData: res.data }, ()=>{
        //       this.$refs.xTable.clearCheckboxRow() //清除所有行选中
        //     }).initSocket()
        //   }
        // })
      } else {
        this.$message.error('只能选择一条打印！');
      }
    },
    // 波次打印
    printWavePick() {
      if (this.wavePickingCode !== '') {
        const reg = /^BC[\d]{15}$/
        if(reg.test(this.wavePickingCode)) {
          getInfoByWavePickingCode(this.wavePickingCode).then(res=>{
            localStorage.setItem('printData', JSON.stringify(res.data))
            const routeUrl = this.$router.resolve({ path: '/printResult' })
            soonPrint(routeUrl.href)
          })
        } else {
          this.$message.error('波次号格式不正确！')
        }
      }
        // this.$prompt('请输入波次号', '提示', {
        //   confirmButtonText: '确定',
        //   cancelButtonText: '取消',
        //   inputPlaceholder: '请输入波次号',
        //   inputPattern: /^BC[\d]{15}$/,
        //   inputErrorMessage: '波次号格式不正确'
        // }).then(({ value }) => {
        //   getInfoByWavePickingCode(value).then(res=>{
        //     localStorage.setItem('printData', JSON.stringify(res.data))
        //     const routeUrl = this.$router.resolve({ path: '/printResult' })
        //     soonPrint(routeUrl.href)
        //   })
        // }).catch(() => {})
    },
    openClosePrintMode() {
      this.printExpressBillmodel = !this.printExpressBillmodel
    },
    // 翻译状态
    formatterStatus({ cellValue }) {
      if (cellValue === '0') {
        return '待拣货'
      }
      if (cellValue === '1') {
        return '拣货中'
      }
      if (cellValue === '2') {
        return '拣货完成'
      }

    },
    formatterIssue({cellValue}){
      if(cellValue == '0'){
        return '否'
      }else if(cellValue == '1'){
        return  '是'
      }
      return cellValue
    },
    changeDate(value, prefix) {
      if (value) {
        this.listQuery[`${prefix}Start`] = value[0]
        this.listQuery[`${prefix}End`] = value[1]
      } else {
        this.listQuery[`${prefix}Start`] = "";
        this.listQuery[`${prefix}End`] = "";
      }
    },
    //获取列表
    findList() {
      this.loading = true
      return pickingList(this.listQuery).then(response => {
        this.tableData = response.data.records
        this.listQuery.total = response.data.total
        this.loading = false
        this.initFinishFlag = true;
      }).finally(()=> this.needLoadList = true)
    },
    // 排序
    sortList({ column, property, order }) {
      if (order) {
        this.listQuery.sortField = property
        this.listQuery.sortType = order
      } else {
        this.listQuery.sortField = ''
      }
      this.findList()
    },
    // 详情方法
    funcDetail(code, wavePickingCode, temporaryCode) {
      let path = ''
      if (temporaryCode) {
        path = '/wms/waveNumber'
      } else {
        path = '/wms/pickingDetail'
      }
      // const path = wavePickingCode ? '/wms/waveNumber' : '/wms/pickingDetail'
      this.$router.push({
        path,
        query: { code: code, wavePickingCode}
      });
    },
    // 拣货确认
    funcCheck(code, wavePickingCode, temporaryCode) {
      let path = ''
      if (temporaryCode) {
        path = '/wms/waveNumberCheck'
      } else {
        path = '/wms/pickingCheck'
      }
      // const path = wavePickingCode ? '/wms/waveNumberCheck' : '/wms/pickingCheck'
      this.$router.push({
        path,
        query: { code: code, wavePickingCode}
      });
    },
    formatType({cellValue, row}){

      if(cellValue == '0'){
        return '销售发货';
      }
      if(cellValue == '1'){
        return '报损发货';
      }

      if(cellValue == '2'){
        return '领用发货';
      }
      if(cellValue == '3'){
        return '盘亏发货';
      }
      if(cellValue == '5'){
        return '调拨发货';
      }
    },
    formatterOrderTag({ row, cellValue }) {
      let val = row.orderTag;
      this.orderTagList.forEach(e=>{
        if(row.orderTag == e.code){
          val =  e.name;
          return;
        }
      })
      return val;
    },
    // 单个下发
    funcCreateTask(code){
      let params = {
        taskType: 'PICKING',
        sourceCode: code
      }
      createTask(params).then((response)=>{
        this.$message({ dangerouslyUseHTMLString: true,message: response.msg, type: 'success'})
        this.findList()
      })
    },

    // 拣货批量下发
    funcCreateBatchTask(taskType){
      let selectRecords = this.$refs.xTable.getCheckboxRecords()
      if(selectRecords.length == 0){
        this.$message.error("请选择要下发的单据!");
        return
      }
      let codes = []
      selectRecords.forEach( i => {
        codes.push(i.code)
      })

      let params = {
        taskType: taskType,
        sourceCodes: codes
      }
      createBatchTask(params).then((response)=>{
        this.$message({ dangerouslyUseHTMLString: true,message: response.msg, type: 'success'})
        this.findList()
      })
    },

    // 公共取消
    fatherCancel(modelFlag) {
      switch (modelFlag) {
        case 'add':
          this.modelAddFlag = false
          break
        case 'edit':
          this.modelEditFlag = false
          break
        case 'detail':
          this.modelDetailFlag = false
          break
        default:
      }
    },
    // 分页handle
    handlePageChange({ currentPage, pageSize }) {
      this.listQuery.pageNum = currentPage
      this.listQuery.pageSize = pageSize
      this.findList()
    },
    // 底部颜色设置
   /*  footerCellClassName({ $rowIndex, column, columnIndex }) {
      if (columnIndex === 0) {
        if ($rowIndex === 0) {
          return 'col-blue'
        } else {
          return 'col-red'
        }
      }
    }, */
    // 设置底部合计
    footerMethod({ columns, data }) {
      return [
        columns.map((column, columnIndex) => {
          if (columnIndex === 0) {
            return '合计'
          }
          if (['pageviews', 'forecast'].includes(column.property)) {
            return XEUtils.sum(data, column.property)
          }
          return null
        })
      ]
    }
  },
  destroyed() {
    this.$eventBus.$off('refreshList')
  },
}
</script>

<style>
.vxe-table .vxe-body--column:not(.col--ellipsis), .vxe-table .vxe-footer--column:not(.col--ellipsis), .vxe-table .vxe-header--column:not(.col--ellipsis) {
 padding: 6px 0;
}
</style>
<style lang="scss" scoped>
.wavePickingCode {
  width: 200px;
  margin: 0 10px;
}
</style>
